;(function($, scope){
	scope['Search'] = {
		init : function(){
			
		},
		Event:{
			lessOpacity:function(){
			
			},
			moreOpacity:function(){
			
			}
			
		},
		obj:{
			
		},
		data:{
			alias: null
		}
	}
})(jQuery, main);

App.factory('SearchService', ['$http', function ($http) {
    return {
        getResults: function (url) {
			return $http.get(url).success(function(res) {
				
			}).error(function(data){
			
			});
        }
    }
}]);
App.controller('Search', ['$scope', '$filter','SearchService', function ($scope, $filter, TypeSeach) {
	$scope.baseUrl = main.templateURL;
    $scope.loadData = function () {
		var url = main.templateURL+"/api/search?page="+$scope.page+"&per_page="+$scope.per_page+"&callback=JSON_CALLBACK";
        TypeSeach.getResults(url).then(function (response) {
			var res = response.data;
			if(res.error){
				$scope.more = false;
				$scope.articles = [];
			}else{
				$scope.more = res.data.length === $scope.per_page;
				$scope.articles = $scope.articles.concat(res.data);
				
			}
		});
    }
	$scope.setHeaderSearch = function(){
		if(main.Search.data.alias == null ){
			$scope.headerSearch = "...";
		}else{
			$scope.headerSearch = 'Result for "'+main.Search.data.alias+'"';
		}
	};
	$scope.articles = [];
	$scope.setHeaderSearch();
	$scope.loadData();
	
}]);
